package pref.junx.flybird.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.List;

import pref.junx.flybird.R;
import pref.junx.flybird.activity.fri_msg.Fri_Info_Actvity;
import pref.junx.flybird.entity.User_idea;
import pref.junx.flybird.util.ExpandableViewHoldersUtil;

/**
 * Created by JunX on 17/5/13.
 */

public class SimpleAdapter_fri extends RecyclerView.Adapter<SimpleAdapter_fri.SimpleViewHolder> {

    private List<User_idea> data;
    private Context context;


    public SimpleAdapter_fri(Context context, List<User_idea> data) {

        this.context = context;
        this.data = data;

    }

    @Override
    public SimpleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_simple_fei, parent, false);
        SimpleViewHolder holder = new SimpleViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(SimpleViewHolder holder, int position) {
        holder.bind(position);
        holder.nick.setText(data.get(position).getUser_nick());
        holder.phone.setText(" @phone:"+data.get(position).getPhone());

    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class SimpleViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, ExpandableViewHoldersUtil.Expandable, ExpandableViewHoldersUtil.ExpandableTop {

        LinearLayout submit_view;

        RelativeLayout top_view;

        TextView nick;

        TextView phone;

        TextView more;


        public SimpleViewHolder(View view) {
            super(view);
            view.setOnClickListener(this);
;           more=(TextView) view.findViewById(R.id.more_fri);
            nick=(TextView) view.findViewById(R.id.fri_nick);
            phone = (TextView) view.findViewById(R.id.fri_phone);
             more.setOnClickListener(this);
        }



        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.more_fri:

                    Intent intent = new Intent();
                    intent.setClass(context, Fri_Info_Actvity.class);
                    intent.putExtra("id",data.get(getAdapterPosition()).getUser_id());
                    intent.putExtra("nick", data.get(getAdapterPosition()).getUser_nick());
                    intent.putExtra("number", data.get(getAdapterPosition()).getUser_name());
                    intent.putExtra("phone", data.get(getAdapterPosition()).getPhone());
                    intent.putExtra("email", data.get(getAdapterPosition()).getEmail());
                    intent.putExtra("sex", data.get(getAdapterPosition()).getSex());
                    context.startActivity(intent);
                    break;
            }
        }

        public void bind(int pos) {


        }

        @Override
        public View getExpandView() {
            return submit_view;
        }

        @Override
        public View getExpandTopView() {
            return top_view;
        }
    }

}
